#include "user.h"

User::User()
{
	id = 0;
}

/**
  *	A copy constructor
  */
User::User(const User& old)
{
	id = old.id;
	name = old.name;
	colour = old.colour;
	ip = old.ip;
	port = old.port;
	online = old.online;
}

/**
  * Constructs a new user, given a name and colour
  * (For local use)
  */
User::User(QString newName, QColor newColour)
{
	id = 0;
	name = newName;
	colour = newColour;
}

User::User(int newId, QString newName, QColor newColour)
{
        id = newId;
        name = newName;
        colour = newColour;
}

/**
  * Constructs a new user, given the info recieved from the server
  */
User::User(int newId, QString newName, QColor newColour, QString newIp, int newPort, bool newOnline)
{
	id = newId;
	name = newName;
	colour = newColour;
	ip = newIp;
	port = newPort;
	online = newOnline;
}

QString User::getAll()
{
    QString userLine = "";

    userLine = QString::number(id) + ":" + name + ":";

    int r = colour.red();
    int g = colour.green();
    int b = colour.blue();
    int a = colour.alpha();

    userLine+= QString::number(r) + "*" + QString::number(g) + "*" + QString::number(b) + "*" + QString::number(a) + ":";

    if(online)
        userLine+="1";
    else
        userLine+="0";

    return userLine;
}
